using MediatR;
using SumerCoreDevOps.Application.Users.Commands;
using SumerCoreDevOps.Domain.Entities;
using SumerCoreDevOps.Infrastructure.Identity;

namespace SumerCoreDevOps.Application.Users.Handlers;

/// <summary>
/// 创建用户命令处理器
/// </summary>
public class CreateUserCommandHandler : IRequestHandler<CreateUserCommand, User>
{
    private readonly UserManager _userManager;

    public CreateUserCommandHandler(UserManager userManager)
    {
        _userManager = userManager;
    }

    public async Task<User> Handle(CreateUserCommand request, CancellationToken cancellationToken)
    {
        return await _userManager.CreateUserAsync(
            request.Username,
            request.Email,
            request.Password,
            request.DisplayName,
            request.PhoneNumber,
            request.CreatedBy
        );
    }
}
